home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_thread_cond.h.z / apr_thread_cond.h
C/C++ Source or Header  |  2002-07-08  |  7KB  |  166 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_THREAD_COND_H
  56. #define APR_THREAD_COND_H
  57.  
  58. #include "apr.h"
  59. #include "apr_pools.h"
  60. #include "apr_errno.h"
  61. #include "apr_time.h"
  62. #include "apr_thread_mutex.h"
  63.  
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif /* __cplusplus */
  67.  
  68. #if APR_HAS_THREADS
  69.  
  70. /**
  71.  * @file apr_thread_cond.h
  72.  * @brief APR Condition Variable Routines
  73.  */
  74.  
  75. /**
  76.  * @defgroup APR_Cond Condition Variable Routines
  77.  * @ingroup APR
  78.  * @{
  79.  */
  80.  
  81. typedef struct apr_thread_cond_t apr_thread_cond_t;
  82.  
  83. /*   Function definitions */
  84.  
  85. /**
  86.  * Create and initialize a condition variable that can be used to signal
  87.  * and schedule threads in a single process.
  88.  * @param cond the memory address where the newly created condition variable
  89.  *        will be stored.
  90.  * @param pool the pool from which to allocate the mutex.
  91.  */
  92. APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
  93.                                                  apr_pool_t *pool);
  94.  
  95. /**
  96.  * Put the active calling thread to sleep until signaled to wake up. Each
  97.  * condition variable must be associated with a mutex, and that mutex must
  98.  * be locked before  calling this function, or the behavior will be
  99.  * undefined. As the calling thread is put to sleep, the given mutex
  100.  * will be simultaneously released; and as this thread wakes up the lock
  101.  * is again simultaneously acquired.
  102.  * @param cond the condition variable on which to block.
  103.  * @param mutex the mutex that must be locked upon entering this function,
  104.  *        is released while the thread is asleep, and is again acquired before
  105.  *        returning from this function.
  106.  */
  107. APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
  108.                                                apr_thread_mutex_t *mutex);
  109.  
  110. /**
  111.  * Put the active calling thread to sleep until signaled to wake up or
  112.  * the timeout is reached. Each condition variable must be associated
  113.  * with a mutex, and that mutex must be locked before calling this
  114.  * function, or the behavior will be undefined. As the calling thread
  115.  * is put to sleep, the given mutex will be simultaneously released;
  116.  * and as this thread wakes up the lock is again simultaneously acquired.
  117.  * @param cond the condition variable on which to block.
  118.  * @param mutex the mutex that must be locked upon entering this function,
  119.  *        is released while the thread is asleep, and is again acquired before
  120.  *        returning from this function.
  121.  * @param timeout The amount of time in microseconds to wait. This is 
  122.  *        a maximum, not a minimum. If the condition is signaled, we 
  123.  *        will wake up before this time, otherwise the error APR_TIMEUP
  124.  *        is returned.
  125.  */
  126. APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
  127.                                                     apr_thread_mutex_t *mutex,
  128.                                                     apr_interval_time_t timeout);
  129.  
  130. /**
  131.  * Signals a singla thread, if one exists, that is blocking on the given
  132.  * condition variable. That thread is then scheduled to wake up and acquire
  133.  * the associated mutex. Although it is not required, if predictible schedule
  134.  * is desired, that mutex must be locked while calling this function.
  135.  * @param cond the condition variable on which to produce the signal.
  136.  */
  137. APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond);
  138.  
  139. /**
  140.  * Signals all threads blocking on the given condition variable.
  141.  * Each thread that was signaled is then schedule to wake up and acquire
  142.  * the associated mutex. This will happen in a serialized manner.
  143.  * @param cond the condition variable on which to produce the broadcast.
  144.  */
  145. APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond);
  146.  
  147. /**
  148.  * Destroy the condition variable and free the associated memory.
  149.  * @param cond the condition variable to destroy.
  150.  */
  151. APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond);
  152.  
  153. /**
  154.  * Get the pool used by this thread_cond.
  155.  * @return apr_pool_t the pool
  156.  */
  157. APR_POOL_DECLARE_ACCESSOR(thread_cond);
  158.  
  159. #endif /* APR_HAS_THREADS */
  160.  
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164.  
  165. #endif  /* ! APR_THREAD_COND_H */
  166.